<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>景深</title>
  <style>
    .back,
    .content {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      perspective:4000px;
    }

    .back {
      background-image: url(https://goss3.vcg.com/creative/vcg/400/new/8a0aa5d3addd48228503c253d4728665.jpg);
      background-size: contain;
      background-position: center;
      background-repeat: no-repeat;
      background-color: brown;
      /* rotate3d(1, 0, 0, 30deg) */
      transform: scale(.9);
    }
  </style>
</head>
<body>
  <div class="content">
    <div class="back"></div>
  </div>
  <script>
  var b = document.querySelector('.back');
  window.addEventListener('deviceorientation',function (event) {
    var x = event.gamma;
    var y = event.beta;

    if (Math.abs(x) > 30) {
      return
    }
    if (Math.abs(y) > 30) {
      return
    }

    b.style.transform = 'scale(.9) translate('+ x +'px, '+y+'px)' +

    console.log(x, b.style)
  });
  </script>
</body>
</html>
